<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>


<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">

            <form class="layui-form " action="">
                <input type="hidden" name="id" value="{$item.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="cases_name" value="{$item.cases_name}" class="layui-input" lay-verify="required">
                    </div>
                </div>




                <div class="layui-form-item" >

                    <div class="layui-inline">
                        <label class="layui-form-label">户型</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <input type="text" name="house_type" value="{$item.house_type}" class="layui-input" lay-verify="required" placeholder="请输入">
                        </div>

                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">面积</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <input type="text" name="area" value="{$item.area}" class="layui-input" lay-verify="required" placeholder="请输入">
                        </div>
                        <div class="layui-form-mid">㎡</div>
                    </div>

                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">缩略图片</label>

                    <div class="layui-input-inline " style="width: auto;">

                        <div class="layui-upload-drag" id="pic1" style="padding: 2px">
                            <img class="layui-upload-img"
                                 style="width: auto;height: 120px; object-fit: cover;"
                                 src="{$item.small_img2}">
                            <input type="hidden" name="small_img" value="{$item.small_img}">
                        </div>
                    </div>
                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label">案例内容</label>
                    <div class="layui-input-block">
                        <a class="layui-btn" data_id="{$item.id}" onclick="hre(this)">查看</a>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-input-inline" style="width: 300px !important;">
                        <label class="layui-form-label">收藏人数</label>
                        <div class="layui-input-block">
                            <input type="text" name="collect_number" value="{$item.collect_number}" class="layui-input" lay-verify="required">
                        </div>
                    </div>

                    <!--<div class="layui-input-inline" style="width: 530px !important;">-->
                    <!--<label class="layui-form-label">发布时间</label>-->
                    <!--<div class="layui-input-block">-->
                    <!--<input type="text" class="layui-input" id="time" name="create_time" value="{$item.create_time}"-->
                    <!--lay-verify="required">-->
                    <!--</div>-->
                    <!--</div>-->
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="status" value="1" lay-skin="primary"
                               title="发布"
                               {eq name="$item.status" value="1"}
                               checked
                               {else/}
                               {/eq}
                        >
                        <input type="checkbox" name="remen" value="1"  lay-skin="primary"
                               title="设为热门"
                               {eq name="$item.remen" value="1"}
                               checked
                               {else/}
                               {/eq}
                        >
                    </div>
                </div>


                <!--<div class="layui-form-item">-->
                <!--<label class="layui-form-label">区域</label>-->
                <!--<div class="layui-input-inline" style="width: 25% !important;">-->
                <!--<select name="sheng" lay-verify="required">-->
                <!--&lt;!&ndash;<option value="">请选择省</option>&ndash;&gt;-->
                <!--<option value="河南省" selected="">河南省</option>-->
                <!--</select>-->
                <!--</div>-->
                <!--<div class="layui-input-inline" style="width: 25% !important;">-->
                <!--<select name="shi" lay-verify="required">-->
                <!--&lt;!&ndash;<option value="">请选择市</option>&ndash;&gt;-->
                <!--<option value="周口市">周口市</option>-->
                <!--</select>-->
                <!--</div>-->
                <!--<div class="layui-input-inline" style="width: 25% !important;">-->
                <!--<select name="xian" lay-verify="required">-->
                <!--&lt;!&ndash;<option value="">请选择县/区</option>&ndash;&gt;-->
                <!--<option value="川汇区">川汇区</option>-->
                <!--<option value="东新区">东新区</option>-->

                <!--</select>-->
                <!--</div>-->
                <!--</div>-->

                <!--<div class="layui-form-item">-->
                <!--<label class="layui-form-label">详细地址</label>-->
                <!--<div class="layui-input-block">-->
                <!--<input type="text" name="address" value="{$item.address}" class="layui-input" lay-verify="required">-->
                <!--</div>-->
                <!--</div>-->

                <div class="layui-form-item" style="background-color: #f4f4f4;height: 60px;padding-top: 20px">

                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="cases">确认保存</button>
                        <!--<button type="reset" class="layui-btn layui-btn-primary">重新填写</button>-->
                    </div>
                </div>

            </form>


        </div>


    </div>
</div>


<script>


    layui.use(['form', 'upload', 'laydate'], function () {
        var $ = layui.$
            , layer = layui.layer
            , form = layui.form;
        var upload = layui.upload;
        var laydate = layui.laydate;


        //网站设置
        //监听submit提交
        form.on('submit(cases)', function (obj) {
            //提交复选框中选中的值
            var groupCheckbox_s=$("input[name='status']");
            console.log(groupCheckbox_s+'yyyyy');
            var fabu="";
            for(var i=0;i<groupCheckbox_s.length;i++){
                if(groupCheckbox_s[i].checked){
                    var val =groupCheckbox_s[i].value;
                    if(fabu.length>0){
                        fabu+=","+val;
                    }else{
                        fabu+=val;
                    }

                }
            }
            var groupCheckbox_r=$("input[name='remen']");
            console.log(groupCheckbox_r+'yyyyy');
            var remen="";
            for(var i=0;i<groupCheckbox_r.length;i++){
                if(groupCheckbox_r[i].checked){
                    var val =groupCheckbox_r[i].value;
                    if(remen.length>0){
                        remen+=","+val;
                    }else{
                        remen+=val;
                    }

                }
            }
            obj.field['status']=fabu;
            obj.field['remen']=remen;
//            layer.msg(JSON.stringify(obj.field)); obj.field为当前容器的全部表单字段，名值对形式：{name: value}
            $.post("{:url('edit_cases')}", obj.field, function (res) {

                if (res.code == 1) {

                    //将数据传入到父元素
//                        parent.app.items.push(data.field);
//                        $('.layui-form')[0].reset();
//                        $('#phone').val('');
                    parent.init();
                    parent.layer.msg(res.msg, {icon: 1})

                    return false;
                } else {
                    parent.layer.msg(res.msg, {icon: 2})
                    return false;
                }

            });
            return false;
        });

        //拖拽上传
        upload.render({
            elem: '#pic1'
            , url: '/tool/qiniu/upload'
            , before: function () {
                layer.load(2);
            }
            , done: function (res) {
                layer.closeAll();
                console.log(res)
                $('#pic1 img').attr('src', res.data.url);//完整url
                $('#pic1 input').val(res.data.pic);//存入数据库中的部分url
            }
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#time' //指定元素
        });
    });

    function hre(that) {
        var id=$(that).attr('data_id');
//        location.href="{:url('detail')}?id="+id;
        layer.open({

            type: 2,
            title: '案例详情',
            shadeClose: true,
            shade: 0.01,
            area: ['80%', '80%'],
            content: "{:url('detail_cases')}?id="+id //iframe的url

        })
    }

    //获取复选框选中的值
    var ff = "{$item.status}";
    var check_s = ff.split(",");
    var groupCheckbox_s = $("input[name='status']");
    $(function () {
        for (var i=0;i<groupCheckbox_s.length;i++){
            var val = groupCheckbox_s[i].value;
            if (check_s.indexOf(val) != -1){
                groupCheckbox_s[i].checked=true;
            }
        }
    })
    var rr = "{$item.remen}";
    var check_r = rr.split(",");
    var groupCheckbox_r = $("input[name='remen']");
    $(function () {
        for (var i=0;i<groupCheckbox_r.length;i++){
            var val =groupCheckbox_r[i].value;
            if (check_r.indexOf(val) != -1){
                groupCheckbox_r[i].checked=true;
            }
        }
    })

</script>





